#include <stdio.h>
#include <stdlib.h>

#define INF -1

class Data {
  public:

    Data(const int size);
    Data(const double **table) {};
    ~Data();
    void PrintTable();
    void Normalize();
    double min(const double x, const double y) {if(x > y) return y; else return x;}
    int GetTableSize() {};
    void GetPath(double *path) {};
        
  private:
    int table_size;
    double **table;
    bool *nodeleted_vertixes;
    int *path;

    void WriteCosts(double **table,int table_size);
    double GetMinCost(double **table) {};
};

int main() {
  Data task = 10;
  
  task.Normalize();
  task.PrintTable();
  return 0;
}

void Data::WriteCosts(double **table, int table_size) {
  int i,j;
  
  for(i=0;i<table_size;++i) {
    //Finding min value in i th string:
    for(j=0;j<table_size,table[i][j]==INF;++j) {}; //Finding the number of first value x != INF
    table[i][table_size] = table[i][j]; //x is a start min value
    for(;j<table_size;++j) {
      if (table[i][j] != INF) {
        table[i][table_size] = this->min(table[i][table_size],table[i][j]);
      }
    }
    //a[i][j] minus min value:
    for(j=0;j<table_size;++j)
      table[table_size][table_size] += table[i][table_size]; //Sum min cost
  }
  //The same actions as above with the columns:
  for(i=0;i<table_size;++i) {
    for(j=0;j<table_size,table[j][i]==INF;++j) {};
    table[table_size][i] = table[j][i];
    for(;j<table_size;++j) {
      if (table[j][i] != INF) {
        table[table_size][i] = this->min(table[table_size][i],table[j][i]);
      }
    }
    for(j=0;j<table_size;++j)
      table[table_size][table_size] += table[table_size][i];
  }
} 

//double Table::GetMinCost(double **table) {
  

Data::Data(int size) {
  int i,j;

  this->table_size = size;
  table = (double **)malloc((size+1)*sizeof(double *));

  for(i=0;i<=size;++i) 
    table[i] = (double *)malloc((size+1)*sizeof(double));
  
  for(i=0;i<size;++i)
    for(j=0;j<size;++j) {
      if (i != j) table[i][j] = static_cast<double>(rand()%100);//-(rand()%100);
        else table[i][j] = INF;
    }

  nodeleted_vertixes = (bool *)malloc(size*sizeof(bool));
  for(i=0;i<size;++i) nodeleted_vertixes[i] = 1;
}

Data::~Data() {
  int i;
  
  for(i=0;i<table_size;++i) 
    free(table[i]);
  free(table);
}

void Data::PrintTable() {
  int i,j;

  for(i=0;i<=table_size;++i) {
    for(j=0;j<=table_size;++j)
      printf("%.0f\t",table[i][j]);
    printf("\n");
  }
}

void Data::Normalize() {
  WriteCosts(this->table,this->table_size);
}
